package io.renren.modules;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Test {
    public static void main(String[] args) {

        List<Integer> list = new CopyOnWriteArrayList<>();
        for (int i = 0;i < 5;i++){
            list.add(i);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {

                for (Integer integer : list) {
                    System.out.println("线程1="+integer);
                }

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }).start();


        new Thread(new Runnable() {
            @Override
            public void run() {

                for (Integer integer : list) {

                    System.out.println("线程2="+integer);

                }

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                list.remove(1);

            }
        }).start();


       /* try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (Integer integer : list) {
            System.out.println("线程3="+integer);
        }*/

    }
}
